package core.data;

public class DataCollector<T> {
    private T value = null;
    private Runnable test = null;
    public DataCollector(){}
    public DataCollector(T value){
        setValue(value);
    }

    public DataCollector<T> onTest(Runnable action){
        test = action;
        return this;
    }

    private void doTest(){
        if(test != null) test.run();
    }

    public T getValue(){
        return value;
    }
    public DataCollector<T> setValue(T value){
        this.value = value;
        doTest();
        return this;
    }

    public DataCollector<T> getSet(CollectorGetSet<T> action){
        this.setValue(action.apply(this.getValue()));
        return this;
    }

    public DataCollector<T> clear(){
        value = null;
        doTest();
        return this;
    }

}
